<!-- 技师首页——控制台 -->
<template>
	<view class="technician-index-page">
		<block v-if="isPrivacy">
			<xh-privacy title="隐私保护指引" theme="direction" @onHandleAgree="onHandle" background="rgba(0, 0, 0, .5)"
				color="#12CDC2"></xh-privacy>
		</block>
		<!-- 技师设置 -->
		<block v-else>
			<view class="index-hearder">
				<view v-cloak class="online flex-align-center" @click="changeState(false)"
					v-if="technicianDetails.authenticationNot==3&&technicianDetails.status==2">
					<text class="iconfont icon-xuanzhong dot"></text>
					<text class="status">在线</text>
					<image mode="heightFix" src="/static/right-arrow.png"></image>
				</view>
				<view v-cloak class="offline flex-align-center" @click="changeState(true)"
					v-if="technicianDetails.authenticationNot==3&&technicianDetails.status==1">
					<text class="iconfont icon-xuanzhong dot"></text>
					<text class="status">离线</text>
					<image mode="heightFix" src="/static/right-arrow.png"></image>
				</view>
				<view v-cloak class="service flex-align-center" 
					v-if="technicianDetails.authenticationNot==3&&technicianDetails.status==4">
					<text class="iconfont icon-xuanzhong dot"></text>
					<text class="status">服务中</text>
					<image mode="heightFix" src="/static/right-arrow.png"></image>
				</view>
				<view v-cloak class="offlines flex-align-center" v-if="technicianDetails.authenticationNot!==3||technicianDetails.status==3">
					<text></text>
					<text class="status"></text>

				</view>
				<view class="flex-align-center">
					<block v-for="(i, j) in list" :key="j">
						<view class="type-cls flex-column" @click="setClick(i)">
							<image :src="i.img"></image>
							<view style="color:#fff">{{ i.text }}</view>
						</view>
					</block>
				</view>
			</view>
			<!-- 技师员工信息 -->
			<view class="flex-align-center person-all-padding">
				<view class="flex-columns m-left20">
					<view class="v-title">员工信息</view>
					<view @click="auth()" class="flex person-img">

						<block v-if="technicianDetails.authenticationNot!==3">
							<img class="avatar"
								:src="authorizationInformation.avatar?authorizationInformation.avatar:'/static/avatar.png'"
								alt="">
						</block>

						<block v-if="technicianDetails.authenticationNot==3">
							<img class="avatar"
								:src="technicianDetails.head?technicianDetails.head:'/static/avatar.png'" alt="">
						</block>

						<!-- <image
							:src="authorizationInformation.avatar?authorizationInformation.avatar:'/static/avatar.png'">
						</image> -->
					</view>
				</view>
				<view class="flex-columns flex1">
					<view class=" v-title m-left40 m-left20">数据来源</view>
					<view class="flex-wrap width100 m-left20">

						<view class="data-cls">
							<text>今日订单(个)</text>
							<view>
								{{technicianDetails.authenticationNot==3?getSelectTechnicianStatisticsObj.orderCount?getSelectTechnicianStatisticsObj.orderCount:'0':'--'}}
							</view>
						</view>
						<view class="data-cls">
							<text>累计订单数(个)</text>
							<view>
								{{technicianDetails.authenticationNot==3?getSelectTechnicianStatisticsObj.accumulatedOrdersCount?getSelectTechnicianStatisticsObj.accumulatedOrdersCount:'0':'--'}}
							</view>
						</view>


						<view class="data-cls">
							<text>累计订单金额</text>
							<view>
								{{technicianDetails.authenticationNot==3?getSelectTechnicianStatisticsObj.settledAmount?getSelectTechnicianStatisticsObj.settledAmount:'0':'--'}}
							</view>
						</view>


						<view class="data-cls">
							<text>今日订单金额</text>
							<view>
								{{technicianDetails.authenticationNot==3?getSelectTechnicianStatisticsObj.todayMoney?getSelectTechnicianStatisticsObj.todayMoney:'0':'--'}}
							</view>
						</view>

					</view>
				</view>
			</view>
			<!-- 地图 -->

			<!-- <view style="padding: 0 20rpx;" v-if="technicianDetails.authenticationNot==3">
				<view class="signMap ">
					<view>
						<image class="positioning" src="../../static/Vector.jpg" mode=""></image>
						<text style="color: #999;">请实时签到方便平台匹配就近订单</text>
					</view>
					<view class="signBtn" @click="signBtn()">
						签到
					</view>
				</view>

				
				<map @tap="(event)=>taps(event)" style="width: 100%; height: 163px;" :latitude="lat2" :longitude="lng2"
					:markers="covers2"></map>
			</view> -->
			<!-- 统计数据 -->
			<view class="flex-wrap width100">
				<block v-for="(i, j) in statisticsList" :key="j">
					<view v-if="i.text!='联系客服'&& i.withdrawalMethod!==4&&i.withdrawalMethod!==3" class="statistics-cls flex-column"
						@click="toGo(i.url)">


						<image :src="i.img"></image>
						<view>{{ i.text }}</view>


					</view>
					<button v-if="i.text=='联系客服'" open-type="contact" class=" kefubtn"
						style="background-color: #FFFFFF;" @contact="handleContact">
						<view class="flex-column">
							<image src="/static/technician/type6.png"
								style="width: 62rpx;height: 60rpx;margin-bottom: 8rpx;"></image>
							<view>联系客服</view>
						</view>
					</button>
				</block>
			</view>
		</block>
		<!-- 紧急救援 -->
		<sunui-popup ref="pops">
			<template v-slot:content>
				<view class="v-pops-cls">
					<view class="flex-column pops-title">
						<view class="font36">紧急救援</view>
						<view class="flex-align-center s-hint">
							收到后，我们将
							<text>第一时间报警</text>
							为你展开救援
						</view>
					</view>
					<view class="p-pops">地址：{{address}}</view>
					<view class="flex-between p-pops">
						<!-- <text>电话：{{}}</text> -->
						<!-- <view class="green" @click="getPhoneNumber()">重新获取</view> -->
					</view>
					<!-- 当前地图 -->
					<map style="width: 100%; height: 306px;" @tap="taps()" @anchorpointtap='anchorpointtaps()'
						@poitap="poitaps()" :latitude=" latitude" :longitude="longitude" :markers="covers"></map>
					<view class="flex-align-center pops-btn ">
						<view class="v-cancel" @click="popCanel">取消</view>
						<view class="v-confirm" @click="popClose">确认</view>
					</view>
				</view>
			</template>
		</sunui-popup>

		<!-- “忙时设置” 弹框 -->
		<sunui-popup ref="pop">
			<template v-slot:content>
				<!-- <itsCalendar :sta_num="10" :end_num="18" :int_num="15" @getTime="TimeData"></itsCalendar> -->


				<view class="pop-all">
					<view class="demo-block">

						<view class="content">
							<view class="tab">
								<zb-tab :height="50" lineWidth="50px" shrink @click-tab="timeSelectd" :activeStyle="{
											fontWeight: 'bold',
											transform: 'scale(1.1)'
										  }" :data="navTimeList" v-model="active">
								</zb-tab>

							</view>
							<view class="card" v-for="item,index in navTimeList" v-show="item.value==active"
								:key="item.value">
								<view class="pop-hint flex">温馨提示：设置忙时的时间后，该时间段不 能接单</view>

								<busyHourSettingOne :xzTimeOne="xzTimeOne" v-if="item.value===0"></busyHourSettingOne>
								<busyHourSettingTwo v-if="item.value===1" :xzTimeTwo="xzTimeTwo"></busyHourSettingTwo>
								<busyHourSettingThree v-if="item.value===2" :xzTimeThree="xzTimeThree">
								</busyHourSettingThree>
								<busyHourSettingFour v-if="item.value===3" :xzTimeFour="xzTimeFour">
								</busyHourSettingFour>
								<busyHourSettingFive v-if="item.value===4" :xzTimeFive="xzTimeFive">
								</busyHourSettingFive>
								<busyHourSettingSix v-if="item.value===5" :xzTimeSix="xzTimeSix"></busyHourSettingSix>
								<busyHourSettingSeven v-if="item.value===6" :xzTimeSeven="xzTimeSeven">
								</busyHourSettingSeven>

								<view class="fixed-set-btn flex-align-center">
									<checkbox-group @change="changeAll" class="flex checkbox-width">
										<!-- 		<label>
											<checkbox value="all" color="#1890FF" :checked="isAllChecked"></checkbox>
											<text class="iconfont icon-check" v-show="isAllChecked"></text>
										</label> -->

									</checkbox-group>
									<view class="save-btn flex" @click.stop="saveInfo()">保存设置</view>
								</view>

							</view>


						</view>
					</view>

					<!-- 	<scroll-view scroll-x="true">
						<block v-for="(item, index) in dayList" :key="index">
							<view class="dayTitle flex" @click="timeSelectd(index, item)">
								<view class="flex-align-center" :class="current == index ? 'select2' : 'like'">
									<view v-if="index == 0">今天</view>
									<view v-else>周{{ item.week }}</view>
									<view>{{ item.month }}-{{ item.day }}</view>
								</view>
							</view>
						</block>
					</scroll-view> -->


				</view>
			</template>
		</sunui-popup>
		<!-- ‘冻结’ 弹框 -->
		<sunui-popup ref="popFreeze">
			<template v-slot:content>
				<view class="v-pop-freeze flex-column">
					<view class="v-title">提示</view>
					<view class="v-content">你的站点已冻结，请联系管理员</view>
				</view>
			</template>
		</sunui-popup>
		<sunui-popup ref="technicianFreeze">
			<template v-slot:content>
				<view class="v-pop-freeze flex-column">
					<view class="v-title">提示</view>
					<view class="v-content">你的员工端被冻结，请联系管理员</view>
				</view>
			</template>
		</sunui-popup>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapState,
		mapMutations
	} from 'vuex'
	import busyHourSettingOne from '@/components/busyHourSetting/busyHourSettingOne.vue'
	import busyHourSettingTwo from '@/components/busyHourSetting/busyHourSettingTwo.vue'
	import busyHourSettingThree from '@/components/busyHourSetting/busyHourSettingThree.vue'
	import busyHourSettingFour from '@/components/busyHourSetting/busyHourSettingFour.vue'
	import busyHourSettingFive from '@/components/busyHourSetting/busyHourSettingFive.vue'
	import busyHourSettingSix from '@/components/busyHourSetting/busyHourSettingSix.vue'
	import busyHourSettingSeven from '@/components/busyHourSetting/busyHourSettingSeven.vue'

	// import itsCalendar from '@/components/it1998-calendar/it1998-calendar.vue';
	import common from '@/common/js/common.js';
	export default {
		components: {
			/*  */
			busyHourSettingOne,
			busyHourSettingTwo,
			busyHourSettingThree,
			busyHourSettingFour,
			busyHourSettingFive,
			busyHourSettingSix,
			busyHourSettingSeven

		},
		data() {
			return {
				active: 0,
				latitude: '',
				longitude: '',
				form: {},
				address: '',
				address2: '',
				lat2: '',
				lng2: '',
				isPrivacy: uni.getStorageSync("privacy") ? false : true,
				covers: [{
					latitude: '',
					longitude: '',
					iconPath: '/static/Vector-1.png',
					width: 20,
					height: 20
				}],
				covers2: [{
					latitude: '',
					longitude: '',
					iconPath: '/static/Vector-1.png',
					width: 20,
					height: 20
				}],
				list: [{
						img: '/static/technician/console1.png',
						text: '忙时设置',
						id: 1
					},
					{
						img: '/static/technician/console2.png',
						text: '紧急救援',
						id: 2
					},
					{
						img: '/static/technician/console3.png',
						text: '新订单',
						url: '/pages/order/order',
						id: 3
					}
				],
				dataList: [{
						text: '今日完成订单',
						num: 10
					},
					{
						text: '累计完成订单数',
						num: 522
					},
					{
						text: '累计已结算订单金额',
						num: 542.32
					},
					{
						text: '今日订单已完成金额',
						num: 5563
					}
				],
				statisticsList: [{
						img: '/static/technician/type1.png',
						text: '财务统计',
						url: '/pages/statistics/index/index'
					},
					{
						img: '/static/technician/type2.png',
						text: '提现记录',
						url: '/pages/withdrawal/withdrawal-records/withdrawal-records'
					},
					{
						img: '/static/technician/type3.png',
						text: '提现账户',
						url: '/pages/withdrawal/withdrawa-account/withdrawa-account'
					},
					// {
					// 	img: '/static/technician/type4.png',
					// 	text: '服务区域',
					// 	url: '/pages/service-area/service-area'
					// },
					{
						img: '/static/technician/type5.png',
						text: '用户评价',
						url: '/pages/personalInformation/userEvaluate/userEvaluate'
					},
					{
						img: '/static/technician/type6.png',
						text: '联系客服'
					}
				],
				// 技师统计
				getSelectTechnicianStatisticsObj: null,
				uid: '',
				// 日期选择
				current: 0,
				dayList: [],
				xzTime: common.GetNowTime(new Date()),
				week: '',
				// 早上

				morningIndex: 0,
				// 全选框
				isAllChecked: false,

				submitArr: [],
				// 保存时间
				saveTime: [],
				// 保存数组
				saveArr: [],
				withdrawalMethod: null,
				navTimeList: [],
				submitArrAll: [],
				xzTimeOne: '',
				xzTimeTwo: '',
				xzTimeThree: '',
				xzTimeFour: '',
				xzTimeFive: '',
				xzTimeSix: '',
				xzTimeSeven: '',
				orderCount:'',


			};

		},
		
		onShow() {
			this.initData()
			this.init()
			
			// 统计当前的订单
			this.queryOrderFn()
		 
		},
		onLoad() {
			this.uid = uni.getStorageSync('userId');
			this.init()
			// this.getLocations2()

			this.dayList = common.weekDate().dayList;
           

			this.week = '今天';
			// 判断月份是否大于等于10 如果是的则打印，否则补零0
			for (let i = 0; i < this.dayList.length; i++) {
				if (this.dayList[i].day >= 10) {}
				// 补零
				if (this.dayList[i].day < 10) {
					this.dayList[i].day = '0' + this.dayList[i].day;
				}
			}

			const res = this.dayList.map((item, i) => {
				if (i == 0) {
					item = this.week + item.month + '-' + item.day
				} else {
					item = '周' + item.week + item.month + '-' + +item.day
				}
				return {
					name: item,
					value: i
				}
			})
			console.log(JSON.stringify(res) + '===================')

			this.navTimeList = res


		},

		components: {
			// itsCalendar
		},
		computed: {
		
			...mapGetters('user', ['authorizationInformation', 'technicianDetails']),
		
		},
		methods: {
			...mapMutations('user', ['technicianDetailsFn','uploadTaskCenter']),
			async queryOrderFn(){
					console.log('===================进来了=================')
			
				if(this.technicianDetails.authenticationNot==3){
					const result = await this.$http.get({
						url: this.$api.getSelectTechnicianOrder,
						data: {
							page: 1,
							limit: 10,
							orderNumber:'',
							technicianEvaluationId: wx.getStorageSync('technicianId'), //技师id
							status: 1 //订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款
						}
					});
					if(result.code==200){
						this.orderCount=result.data.count
						if(this.orderCount>0){
							uni.setTabBarBadge({
								index:1,
								text:String(this.orderCount)
							})
						}
					}
				}

			},
			
			openSiteFreeze() {
				console.log('进入‘冻结’弹出框');
				this.$refs.popFreeze.show({
					anim: 'center',
					shadeClose: false, //false使用户不能点击其它关闭页面
					topclose: false
				});
			},
			openTechnicianFreeze() {
				console.log('进入‘冻结’弹出框');
				this.$refs.technicianFreeze.show({
					anim: 'center',
					shadeClose: false, //false使用户不能点击其它关闭页面
					topclose: false
				});
			},
			async initData() {
				if (this.technicianDetails.authenticationNot == 3) {
					// 获取技师统计
					const result = await this.$http.get({
						url: this.$api.getSelectTechnicianStatistics,
						data: {
							technicianId: this.uid = uni.getStorageSync('technicianId')
						}
					});

					console.log(result)
					if (result.code == 200) {
						this.getSelectTechnicianStatisticsObj = result.data
					}
				}
				
				// 如果当前状态被冻结那么不然操作
				if(this.technicianDetails.status==3){
					this.openTechnicianFreeze()
				}else{
					this.$refs.technicianFreeze.close()
				}
			},
			// 改变技师状态
			async changeState(state) {
				uni.showModal({
					title: '员工状态',
					content: state ? '是否将状态改为(在线中)' : '是否将状态改为(离线)',
					success: async (res) => {
						if (res.confirm) {
							if (state) {
								this.form = this.technicianDetails
								this.form.status = 2

								// 提交所有的认证信息
								const saveRes = await this.$http.put({
									url: this.$api.technicianModifyIphone,
									data: {
										...this.form
									},

								});
								console.log(saveRes)
							} else {
								this.form = this.technicianDetails
								this.form.status = 1

								// 提交所有的认证信息
								const saveRes = await this.$http.put({
									url: this.$api.technicianModifyIphone,
									data: {
										...this.form
									}
								});
								console.log(saveRes)
							}
						} else if (res.cancel) {

						}

					}
				});

			},


			async init() {
				this.getSiteDomainID()
				// wx.setStorageSync('technicianId', 2);
				// 获取技师id
				this.sharePictures()
				const res = await this.$http.get({
					url: this.$api.getTechnicianId,
					data: {
						userId: this.uid = uni.getStorageSync('userId')
					}
				});

				if (res.code == 200) {
					console.log(res)
					if (res?.data) {

						uni.setStorageSync('technicianId', res?.data.id)

						if (uni.getStorageSync('technicianId')) {
							const technicianId = uni.getStorageSync('technicianId')
							const result = await this.$http.get({
								url: this.$api.queryTechnician + '/' + technicianId,

							});
							console.log(result)
							this.technicianDetail = result.data
							this.technicianDetailsFn(this.technicianDetail ? this.technicianDetail : '')
						}

					}

					// uni.setStorageSync('technicianId',3)
				}


				const ress = await this.$http.get({
					url: this.$api.withdrawalSettings,
					data: {
						siteId: uni.getStorageSync('siteId') // 站点域名(传值将https截取)
					}

				})
				
				console.log('提现方式============' + ress)


				// 提现方式
				this.withdrawalMethod = ress.data?.withdrawalMethod
                console.log(this.withdrawalMethod)
				if(this.withdrawalMethod==3){
					this.statisticsList[2].withdrawalMethod = this.withdrawalMethod
				}else if(this.withdrawalMethod==4){
					this.statisticsList[2].withdrawalMethod = this.withdrawalMethod
					this.statisticsList[1].withdrawalMethod = this.withdrawalMethod
					this.statisticsList[0].withdrawalMethod = this.withdrawalMethod
					console.log(this.withdrawalMethod)
				}
				uni.setStorageSync('withdrawalMethod', ress.data)
				
				
				
			},
			// 分享图片 
			async sharePictures(){
				const res = await this.$http.get({
					url: this.$api.sitePlatformConfig,
					data: {
						siteId:uni.getStorageSync('siteId')
					}
				});
				console.log(res.data+'==============分享图片')
				// 分享标题
				wx.setStorageSync('system',res.data )
				// 分享图片
				// wx.setStorageSync('system',res.data.sharePictures)
				// 分享描述
				// wx.setStorageSync('system',res.data.shareDescribe)
			},

			// 根据站点域名查询站点id
			async getSiteDomainID() {
				
         
				const url =this.$api.getSiteDomainName   
				const siteDomainName=url.match(/^(?:https?:\/\/)?([^\/]+)/i)[1];
				// const siteDomainName='yjyksaas.admin168.net'
				console.log(siteDomainName)
				// uploadQualificationForm','uploadHealthCertificateForm','uploadAvatarForm','identityAuthenticationForm
				const result = await this.$http.get({
					url: this.$api.getSiteDomainName,
					data: {
						siteDomainName:siteDomainName // 站点域名(传值将https截取)
					}
				});

				if (result.code == 200) {
					// ‘冻结’弹出框

					if (result.data.siteStatus == '1') {
						this.openSiteFreeze()
					}else{
						this.$refs.popFreeze.close()
					}

					this.siteId = result.data.id;

					uni.setStorageSync('siteId', this.siteId)
					console.log('根据站点域名查询站点result.', result);

				} else {
					this.$sun.toast(result.message)
				}
			},
			
			TimeData(e) {
				console.log(e)
			},

			getLocations() {
				console.log('123')
				uni.getLocation({
					// 将wgs84 改为 gcj02  h5提高精确度
					type: 'gcj02',
					//  geocode: true,   address：地址信息（仅App端支持，需配置geocode为true）
					success: async res => {
						console.log(res)
						this.latitude = res.latitude;
						this.longitude = res.longitude;
						// 获取当前经纬度  存缓存  在计算差距离的时候 调用
						wx.setStorageSync('lat', this.latitude);
						wx.setStorageSync('lng', this.longitude);
						console.log(this.latitude, this.longitude)
						this.covers[0].latitude = this.latitude
						this.covers[0].longitude = this.longitude
						const result = await this.$sun.location({
							lat: this.latitude,
							lng: this.longitude,
							key:wx.getStorageSync('system').tencentMapKey?wx.getStorageSync('system').tencentMapKey:'SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI'
						})
						console.log(result)
						this.address = result.address
					},
					fail: res => {
						console.log('123', res)
						this.lat = res.latitude;
						this.lng = res.longitude;
					}
				});
			},
			onHandle(e) {
				this.isPrivacy = e;
			},
			// 获取到当前地址
			getLocations2() {
				console.log('123')
				uni.getLocation({
					// 将wgs84 改为 gcj02  h5提高精确度
					type: 'gcj02',
					//  geocode: true,   address：地址信息（仅App端支持，需配置geocode为true）
					success: async res => {
						console.log(res)
						this.lat2 = res.latitude;
						this.lng2 = res.longitude;
						console.log(this.lat2, this.lng2)
						this.covers2[0].latitude = this.lat2
						this.covers2[0].longitude = this.lng2

						// 获取当前经纬度  存缓存  在计算差距离的时候 调用
						wx.setStorageSync('lat', this.lat2);
						wx.setStorageSync('lng', this.lng2);
						this.upCallback();
						const result = await this.$sun.location({
							lat: this.lat2,
							lng: this.lng2,
							key: wx.getStorageSync('system').tencentMapKey?wx.getStorageSync('system').tencentMapKey:'SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI'
						})
						console.log(result)
						this.address2 = result.address
						// 查询当前的 技师的状态 如果 并且不值传过去
						console.log(this.technicianDetails)




					},
					fail: res => {
						console.log('123', res)
						this.lat = res.latitude;
						this.lng = res.longitude;
					}
				});
			},
			// 点击获取实时地址
			async currentTapMap2(lat2, lng2) {
				const result = await this.$sun.location({
					lat: lat2,
					lng: lng2,
					key: wx.getStorageSync('system').tencentMapKey?wx.getStorageSync('system').tencentMapKey:'SFABZ-WANWW-FISRY-3IGTF-HV7RE-YSFTI'
				})
				console.log(result)
				this.address2 = result.address
			},

			async signBtn() {
				this.form = this.technicianDetails
				this.form.latitude = this.lat2.toFixed(2);
				this.form.accuracy = this.lng2.toFixed(2);
				// 当前技师状态
				// this.form.latitude=26.46098
				// this.form.accuracy=111.59244
				console.log(this.form)
				// 提交所有的认证信息
				const saveRes = await this.$http.put({
					url: this.$api.technicianModifyIphone,
					data: {
						...this.form
					}
				});
				if (saveRes.code == 200) {
					console.log('result.data', saveRes);
					this.$sun.toast('签到成功当前地址' + this.address2)
					// this.$sun.navGo('/pages/technician/settleIn/settleln-process');
				} else {

					console.log('result.msg', saveRes.msg);
				}
			},
			taps(e) {

				// console.log(e.target.latitude)
				// console.log(e.longitude.longitude)
				this.lat2 = e.target.latitude
				this.lng2 = e.target.longitude
				// 改变标记点
				this.covers2[0].latitude = this.lat2
				this.covers2[0].longitude = this.lng2
				this.currentTapMap2(this.lat2, this.lng2)
			},

			async getPhoneNumber() {
				// 发生验证码
				const result = await this.$http.get({
					url: this.$api.sendSmsRequest,
					data: {
						siteId: uni.getStorageSync('siteId')
					}
				});
				if (result.code == 1) {
					this.$sun.toast(result.msg)
				}else if(result.code == -1){
					this.$sun.toast(result.msg)
				}
			},


			auth() {
				this.handleLogin()
			},
			// 判断登录
			handleLogin() {
				this.uid = uni.getStorageSync('userId');
				if (this.uid) {
					return true;
				} else {
					uni.navigateTo({
						url: `/pages/login/login`
					});
					// 不在跳转到登录页面而是直接用弹框来显示
				}
			},
			// 跳转url
			toGo(url) {
				// 调转之前判断当前是否 已经登录
				console.log(url)
				if (this.handleLogin() && url) {
					// 判断当前的技师状态
					if (this.technicianDetails.authenticationNot == 3) {
						this.$sun.navGo(url);
					} else if (this.technicianDetails.authenticationNot == 4) {
								this.$sun.toast(this.technicianDetails.reasonRejection?'驳回原因:'+this.technicianDetails.reasonRejection:'审核失败请重新提交~')
					} else if (this.technicianDetails.authenticationNot == 2) {

						this.$sun.toast('当前正在审核中，请耐心等待~')
					} else {

						this.$sun.toast('未认证审核前，该功能暂不可用')
						// setTimeout(() => {
						// 	this.$sun.navRe('/pages/my/my');
						// }, 1500)
					}

				}
			},
			// 忙时设置回显

			// 忙时设置 事件
			async setClick(i) {

				if (this.handleLogin()) {
					// 如果在审核中无法展示

					if (this.technicianDetails.authenticationNot == 3) {
						let type = i.id;
						// "忙时设置" 弹出框
						if (type == 1) {

							this.$refs.pop.show({
								anim: 'bottom',
								position: 'bottom',
								topclose: false,
								/* z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面。 */
								titleStyle: 'position: fixed;width: 100%;background: #fff;z-index: 999;border-bottom:1rpx solid #f7f7f7;'
							});
							const result = await this.$http.get({
								url: this.$api.getBySelectBusyHourSetting,
								data: {
									technicianId: uni.getStorageSync('technicianId'),
								}
							});
							console.log(result)
							if (result.code == 200) {
								uni.setStorageSync('timeSelectdArr', result.data)
							}
							this.timeSelectd({
								value: 0
							})

						}
						// "紧急救援" 弹框
						if (type == 2) {
							this.$refs.pops.show({
								anim: 'center',
								shadeClose: false,
								topclose: false,

							});
							this.getLocations()
						}
						// 跳转 “新订单”
						if (type == 3) {
							this.$sun.navSwitch(i.url);
						}
					} else {
						if (this.technicianDetails.authenticationNot == 2) {
							this.$sun.toast('当前正在审核中，请耐心等待~')
						} else if (this.technicianDetails.authenticationNot == 4) {
								this.$sun.toast(this.technicianDetails.reasonRejection?'驳回原因:'+this.technicianDetails.reasonRejection:'审核失败请重新提交~')
						} else {
							this.$sun.toast('未认证审核前，该功能暂不可用')
							// setTimeout(() => {
							// 	this.$sun.navRe('/pages/my/my');
							// }, 3000)
						}
					}
				}

			},


			async saveInfo() {
				// uni.showLoading({
				// 	title: '保存中'
				// })

				console.log(this.saveTime);
				// 取七天的数组内容进行提交
				// busyHourSettingOne,
				// busyHourSettingTwo,
				// busyHourSettingThree,
				// busyHourSettingFour,
				// busyHourSettingFive,
				// busyHourSettingSix,
				// busyHourSettingSeven
				this.submitArrAll = [...uni.getStorageSync('busyHourSettingOne'), ...uni.getStorageSync(
						'busyHourSettingTwo'), ...uni.getStorageSync('busyHourSettingThree'), ...uni
					.getStorageSync('busyHourSettingFour'), ...uni.getStorageSync('busyHourSettingFive'), ...uni
					.getStorageSync('busyHourSettingSix'), ...uni.getStorageSync('busyHourSettingSeven')
				]

				console.log(this.submitArrAll)

				if (uni.getStorageSync('timeSelectdArr')) {
					const timeSelectdArr = uni.getStorageSync('timeSelectdArr').map((item) => {
						const dateTimeString = item.service_time


						// 获取时间部分并去掉末尾的"00"
						const timePart = dateTimeString.replace(/:00$/, '');
						const technicianId = item.technician_id
						return {
							technicianId: technicianId,
							serviceTime: timePart
						}
					})
					console.log(this.dayList)
					const dayArr = this.dayList.map((item) => {
						return item.year + '-' + item.month + '-' + item.day
					});
					// const filteredArray = dayArr.filter((item) => {
					//     return timeSelectdArr.some((val) => {
					//         const parts = val.serviceTime.split('T');
					//         console.log(parts);
					//         return parts[0] === item;
					//     });
					// });
					const filteredArray = timeSelectdArr.filter((item) => {
						return dayArr.some((val) => {
							const parts = item.serviceTime.split('T');
							return parts[0] === val;
						})
					})

					console.log(filteredArray)


					this.submitArrAll = [...this.submitArrAll, ...filteredArray]

					const uniqueArray = Array.from(new Set(this.submitArrAll.map(JSON
						.stringify))).map(JSON
						.parse);

					console.log(uniqueArray)


					const result = await this.$http.post({
						url: this.$api.saveBusyHourSetting,
						data: uniqueArray,

					});

					if (result.code == 200) {
						this.$sun.toast(result.message)
						uni.removeStorageSync('busyHourSettingOne')
						uni.removeStorageSync('busyHourSettingTwo')
						uni.removeStorageSync('busyHourSettingThree')
						uni.removeStorageSync('busyHourSettingFour')
						uni.removeStorageSync('busyHourSettingFive')
						uni.removeStorageSync('busyHourSettingSix')
						uni.removeStorageSync('busyHourSettingSeven')
						uni.hideLoading()
						this.$refs.pop.close();
					}
				} else {
					// 保存
					// const result = await this.$http.post({
					// 	url: this.$api.saveBusyHourSetting,
					// 	data: this.submitArrAll,

					// });
					// console.log(result)
					// if (result.code == 200) {
					// 	this.$sun.toast(result.message)
					// 	uni.removeStorageSync('busyHourSettingOne')
					// 	uni.removeStorageSync('busyHourSettingTwo')
					// 	uni.removeStorageSync('busyHourSettingThree')
					// 	uni.removeStorageSync('busyHourSettingFour')
					// 	uni.removeStorageSync('busyHourSettingFive')
					// 	uni.removeStorageSync('busyHourSettingSix')
					//     uni.removeStorageSync('busyHourSettingSeven')
					// 	uni.hideLoading()
					// 	this.$refs.pop.close();
					// }
				}






			},
			//关闭 "紧急救援" 弹框
			popCanel() {
				this.$refs.pops.close();
			},
			popClose() {
				this.$refs.pops.close();
				this.getPhoneNumber()
			},
			//关闭 "忙时设置" 弹框
			timeSetClose() {
				this.$refs.pop.close();
			},
			// "忙时设置" 日期选择
			timeSelectd(item) {
				console.log(item)
				// console.log(this.dayList)
				// 需要点击的判断是否需要授权
				// this.current = index;


				let date = this.dayList[item.value].year + '-' + this.dayList[item.value].month + '-' + this.dayList[item
					.value].day;
				date = common.GetNowTime(new Date(date));
				// // this.week = '周' + item.week;
				// // // xzTime 当前选择的年月日
				this.xzTimeOne = '',
					this.xzTimeTwo = '';
				this.xzTimeThree = '';
				this.xzTimeFour = '';
				this.xzTimeFive = '';
				this.xzTimeSix = '';
				this.xzTimeSeven = '';
				if (item.value == 0) {
					this.xzTimeOne = date;
				} else if (item.value == 1) {
					this.xzTimeTwo = date;
				} else if (item.value == 2) {
					this.xzTimeThree = date;
				} else if (item.value == 3) {
					this.xzTimeFour = date;
				} else if (item.value == 4) {
					this.xzTimeFive = date;
				} else if (item.value == 5) {
					this.xzTimeSix = date;
				} else if (item.value == 6) {
					this.xzTimeSeven = date;
				}



				// this.$refs.busyHourSettingOne[0].getBySelectBusyHourSetting()
				// console.log(this.xzTime)
				// switchTime
				// this.switchTime()
			},
			switchTime() {


				// const indexFind=this.saveTime.findIndex((item)=>{
				// 	item==this.xzTime
				// })
				console.log(this.submitArr)

				if (uni.getStorageSync('timeSelectdArr').length) {

					const filterTimeIndex = uni.getStorageSync('timeSelectdArr').findIndex((item) => {

						const dateTimeString = item.serviceTime

						const parts = dateTimeString.split('T');
						return parts[0] == this.xzTime
					})
					if (filterTimeIndex !== -1) {
						// 过滤掉所有查询出来的时间并且添加新的时间
						const filterTime = uni.getStorageSync('timeSelectdArr').filter((item) => {

							const parts = item.serviceTime.split('T');
							console.log(parts[0], this.xzTime)
							return parts[0] !== this.xzTime
						})
						console.log(filterTime)
						const uniqueArray = Array.from(new Set(this.saveArr.map(JSON
							.stringify))).map(JSON
							.parse);
						uni.setStorageSync('timeSelectdArr', filterTime)
						this.submitArr = []

						// 对数据进行回显

						this.submitArr = uni.getStorageSync('timeSelectdArr').map((item) => {
							const dateTimeString = item.serviceTime

							const parts = dateTimeString.split('T');
							// 获取日期部分
							const datePart = parts[0];
							this.xzTime = datePart
							// 获取时间部分并去掉末尾的"00"
							const timePart = parts[1]
							return {
								datePart: datePart,
								timePart: timePart
							}
						})

						const filterTimes = this.submitArr.filter((item) => {
							return item.datePart == this.xzTime
						})
						console.log('----------------', filterTime)
						filterTimes.forEach((item) => {
							this.morningData.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeMorningArr.push(i)
								}
							})
							this.noonData.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeNoonArr.push(i)
								}
							})
							this.afternoon.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeAfternoonArr.push(i)
								}
							})
							this.nightData.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeNightArr.push(i)
								}
							})
						})


					} else {
						// this.saveArr = [...uni.getStorageSync('timeSelectdArr'), ...this.submitArr]
						// 对时间进行匹配
						this.saveArr = []
						this.seleTimeMorningArr = []
						this.seleTimeNoonArr = []
						this.seleTimeAfternoonArr = []
						this.seleTimeNightArr = []
						// 进行过滤 
						const uniqueArray = Array.from(new Set(uni.getStorageSync('timeSelectdArr').map(JSON
							.stringify))).map(JSON
							.parse);
						uni.setStorageSync('timeSelectdArr', uniqueArray)
						this.submitArr = []

						this.submitArr = uni.getStorageSync('timeSelectdArr').map((item) => {
							const dateTimeString = item.serviceTime

							const parts = dateTimeString.split('T');
							// 获取日期部分
							const datePart = parts[0];
							this.xzTime = datePart
							// 获取时间部分并去掉末尾的"00"
							const timePart = parts[1]
							return {
								datePart: datePart,
								timePart: timePart
							}
						})

						const filterTimes = this.submitArr.filter((item) => {
							return item.datePart == this.xzTime
						})
						console.log('----------------', filterTimes)
						filterTimes.forEach((item) => {
							this.morningData.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeMorningArr.push(i)
								}
							})
							this.noonData.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeNoonArr.push(i)
								}
							})
							this.afternoon.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeAfternoonArr.push(i)
								}
							})
							this.nightData.forEach((i) => {
								if (item.timePart == i) {
									this.seleTimeNightArr.push(i)
								}
							})
						})

					}
				} else {

					console.log(this.saveArr)
					console.log(this.submitArr)
					this.saveArr = [...this.saveArr, ...this.submitArr]
					// // 对时间进行匹配
					console.log(this.saveArr)
					// // 进行过滤 
					const uniqueArray = Array.from(new Set(this.saveArr.map(JSON
						.stringify))).map(JSON
						.parse);
					uni.setStorageSync('timeSelectdArr', uniqueArray)
					this.saveArr = []
					this.seleTimeMorningArr = []
					this.seleTimeNoonArr = []
					this.seleTimeAfternoonArr = []
					this.seleTimeNightArr = []
				}





			},
			//"忙时设置" 日期选择——点击全选复选框
			changeAll(e) {
				this.isAllChecked = this.isAllChecked == true ? false : true;
				if (this.isAllChecked) {

					this.seleTimeMorningArr = JSON.parse(JSON.stringify(this.morningData))
					this.seleTimeNoonArr = JSON.parse(JSON.stringify(this.noonData))
					this.seleTimeAfternoonArr = JSON.parse(JSON.stringify(this.afternoon))
					this.seleTimeNightArr = JSON.parse(JSON.stringify(this.nightData))
				} else {

					this.seleTimeMorningArr = []
					this.seleTimeNoonArr = []
					this.seleTimeAfternoonArr = []
					this.seleTimeNightArr = []
				}
			}

		}
	};
</script>

<style lang="less">
	[v-cloak] {
		display: none;
	}

	// 冻结弹框
	.v-pop-freeze {
		background: #fff;
		width: 600rpx;
		border-radius: 20rpx;

		.v-title {
			width: 100%;
			text-align: center;
			border-bottom: 2rpx solid #e1e1e1;
			padding: 30rpx 0 20rpx;
			font-size: 30rpx;
			font-weight: bold;
		}

		.v-content {
			padding: 30rpx 0;
			text-align: center;
		}
	}

	;

	.technician-index-page {
		.kefubtn {

			border: none;
			margin: 87rpx 0 0 0;
			background-color: #fff;

			border-radius: 0;

		}

		button::after {

			border: none;

		}

		// 技师设置
		.index-hearder {
			margin: 0 20rpx 40rpx;
			border-radius: 20rpx;
			background: linear-gradient(91deg, #7e9dff 0.43%, #406eff 99.09%);
			box-shadow: 0rpx 6rpx 18rpx 0rpx rgba(2, 46, 187, 0.31);
			height: 278rpx;
			padding: 1px;

			.online {
				margin: 24rpx 28rpx 36rpx;
				background-color: #fff;
				width: 128rpx;
				padding: 6rpx 14rpx;
				border: 2rpx solid #fff;
				border-radius: 70rpx;
				width: 102rpx;

				height: 36rpx;

				.dot {
					font-size: 12rpx;
					margin-right: 4rpx;
					color: #26c278;
					vertical-align: middle;

				}

				.status {
					margin: 0 6rpx;
					color: #333;
					font-size: 24rpx;
				}

				image {
					height: 20rpx;
				}
			}
            .service {
            	margin: 24rpx 28rpx 36rpx;
            	background-color: #fff;
            	width: 120rpx;
            	padding: 6rpx 14rpx;
            	border: 2rpx solid #fff;
            	border-radius: 70rpx;
            
            
            	height: 36rpx;
            
            	.dot {
            		font-size: 12rpx;
            		margin-right: 4rpx;
            		color: #1890FF;
            		vertical-align: middle;
            
            	}
            
            	.status {
            		margin: 0 6rpx;
            		color: #333;
            		font-size: 24rpx;
            	}
            
            	image {
            		height: 20rpx;
            	}
            }


			.offlines {
				margin: 24rpx 28rpx 36rpx;

				width: 102rpx;

				height: 36rpx;
				padding: 6rpx 14rpx;

			}

			.offline {
				margin: 24rpx 28rpx 36rpx;
				background-color: #fff;
				width: 102rpx;

				height: 36rpx;
				padding: 6rpx 14rpx;
				border: 2rpx solid #fff;
				border-radius: 70rpx;

				.dot {
					font-size: 12rpx;
					margin-right: 4rpx;
					color: #D9D9D9;
					vertical-align: middle;

				}

				.status {
					margin: 0 6rpx;
					color: #333;
					font-size: 24rpx;
				}

				image {
					height: 20rpx;
				}
			}

			.onlineshow {
				margin: 24rpx 28rpx 36rpx;


				padding: 6rpx 14rpx;

				border-radius: 70rpx;

				text {
					font-size: 12rpx;
					margin-right: 4rpx;
					color: #26c278;
				}

				view {
					margin: 0 6rpx;
					color: #333;
					font-size: 24rpx;
				}

				image {
					height: 20rpx;
				}
			}

			.type-cls {
				width: calc(100% / 3);

				image {
					width: 56rpx;
					height: 56rpx;
					margin-bottom: 24rpx;
				}

				text {
					color: #fff;
				}
			}
		}

		// 员工信息
		.person-all-padding {
			border-radius: 20rpx;
			// margin: 40rpx 20rpx 0rpx 20rpx;
			padding-bottom: 20rpx;
			background: #fff;
			box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(36, 0, 255, 0.03);

			.v-title {
				color: #333;
				font-size: 32rpx;
				font-weight: 700;
			}

			.person-img {
				background: #f4f4f4;
				margin-top: 18rpx;
				width: 274rpx;
				height: 284rpx;

				image {
					width: 196rpx;
					height: 196rpx;
				}
			}

			.m-left28 {
				margin-bottom: 28rpx;
			}

			.data-cls {
				margin-top: 54rpx;
				width: calc(100% / 2 - 22rpx);
				margin-left: 7rpx;

				text {
					color: #999;
					font-size: 24rpx;
				}

				view {
					padding-right: 20rpx;
					margin-top: 18rpx;
					color: #333;
					font-size: 32rpx;
					font-weight: 700;
				}
			}
		}

		.signMap {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 42rpx 0rpx 20rpx 0rpx;

			.positioning {
				width: 28rpx;
				height: 28rpx;
				vertical-align: middle;
				margin-right: 10rpx;
			}

			.signBtn {
				width: 124rpx;
				height: 56rpx;
				border-radius: 68rpx;
				background: #1890FF;
				text-align: center;
				color: #fff;
				line-height: 56rpx;
			}
		}

		// 统计数据分类
		.statistics-cls {
			width: calc(100% / 4);

			image {
				width: 56rpx;
				height: 56rpx;
				margin: 68rpx 0 24rpx;
			}
		}

		// "忙时设置" 弹框
		.pop-all {
			padding: 48rpx 20rpx 0;
			border-radius: 20rpx 20rpx 0rpx 0rpx;
			background-color: #fff;
			width: 100%;
			height: auto;
			overflow-x: auto;

			scroll-view {
				width: 100%;
				white-space: nowrap;
			}

			.dayTitle {
				min-width: 150rpx;
				border-radius: 60rpx;
				margin-right: 34rpx;
				text-align: center;
				display: inline-block;

				.like,
				.select2 {
					width: 100%;
					height: 100%;

					view {
						font-size: 36rpx;
					}
				}

				.like {
					color: #333;
					font-size: 32rpx !important;
					padding-bottom: 20rpx;
					border-bottom: 8rpx solid #fff;
				}

				.select2 {
					text-align: center;
					padding-bottom: 20rpx;
					border-bottom: 8rpx solid #1890ff;
					color: #1890ff;
				}
			}

			.pop-hint {
				width: 710rpx;
				padding: 18rpx 0rpx;
				color: #1890ff;
				border-radius: 20rpx;
				background: #eef7ff;
				margin: 26rpx 0 40rpx;
			}

			// “早中下晚” 文字样式
			.text-cls {
				font-size: 32rpx;
				min-width: 160rpx;
			}

			.sel-cls,
			.no-cls {
				margin: 0 20rpx 44rpx 0;
				font-size: 32rpx;
				width: 160rpx;
				height: 96rpx;
				border-radius: 20rpx;
			}

			.sel-cls {
				color: #0084fe;
				background: #e1edff;
			}

			.no-cls {
				color: #333;
				background: #f5f5f5;
			}

			.fixed-set-btn {
				height: 116rpx;
				line-height: 116rpx;

				.checkbox-width {
					width: 40%;

					view {
						font-size: 32rpx;
						color: #1890ff;
						margin-left: 20rpx;
					}
				}

				.save-btn {
					width: 60%;
					background: #1890ff;
					color: #fff;
					font-size: 32rpx;
				}
			}
		}

		// “紧急救援” 弹框
		.v-pops-cls {
			width: 700rpx;
			height: auto;
			border-radius: 20rpx;
			background: #fff;

			.pops-title {
				padding: 28rpx 0 20rpx;
				border-bottom: 2rpx solid #ededed;
				margin-bottom: 30rpx;

				.s-hint {
					margin-top: 12rpx;
					color: #666;
					font-size: 24rpx;

					text {
						font-size: 24rpx;
						color: #1e6ceb;
					}
				}
			}

			.p-pops {
				padding: 0 20rpx 30rpx;
			}

			.pops-btn {
				border-top: 2rpx solid #ededed;

				.v-cancel,
				.v-confirm {
					display: flex;
					justify-content: center;
					align-items: center;
					width: calc(100% / 2 - 1px);
					padding: 40rpx 0 30rpx;
				}

				.v-cancel {
					font-size: 32rpx;
					border-right: 2rpx solid #ededed;
				}

				.v-confirm {
					color: #1890ff;
					font-size: 32rpx;
				}
			}
		}
	}
</style>